// by Xeno
//#define __DEBUG__
#define THIS_FILE "fn_initartydlg.sqf"
#include "x_setup.sqf"

#include "x_uiinc.sqf"

private ["_ctrl", "_rank", "_sels", "_magsv", "_ammonv"];

_warty = GVAR(ao_arty_vecs) select 0;
__TRACE_1("_warty","_warty");
_magsv = [];
_cfgmagx = configFile/"CfgMagazines";
{
	if !(_x in _magsv) then {
		_xammo = getText(_cfgmagx/_x/"ammo");
		if (getText(configFile/"CfgAmmo"/_xammo/"submunitionAmmo") != "Mo_ClassicMineRange") then {
			_magsv set [count _magsv, _x];
		};
	};
	__TRACE_1("","_x");
} forEach getArray(configFile/"CfgVehicles"/typeOf _warty/"Turrets"/"MainTurret"/"magazines");

_ammonv = [];
_ammonv resize (count _magsv);
{
	_ammonv set [_forEachIndex, getText(configFile/"CfgMagazines"/_x/"displayName")];
} forEach _magsv;

__TRACE_2("","_magsv","_ammonv");

_ctrl = __uiGetVar(D_ARTI_DISP) displayCtrl 888;

{
	_idx = _ctrl lbAdd _x;
	_ctrl lbSetData [_idx, _magsv select _forEachIndex];
} forEach _ammonv;

_ctrl lbSetCurSel 0;
_ctrl = __uiGetVar(D_ARTI_DISP) displayCtrl 889;
if (!GVAR(with_ranked)) then {
	{_ctrl lbAdd _x} forEach ["1", "2", "3"];
} else {
	_rank = rank player;
	_sels = switch (true) do {
		case (_rank in ["PRIVATE","CORPORAL"]): {["1"]};
		case (_rank in ["SERGEANT","LIEUTENANT"]): {["1", "2"]};
		default {["1", "2", "3"]};
	};
	{_ctrl lbAdd _x} forEach _sels;
};
_ctrl lbSetCurSel 0;
ctrlSetFocus (__uiGetVar(D_ARTI_DISP) displayCtrl 1212);